package com.dao.impl;

import com.dao.ChartDao;
import com.dao.ChartRedisDao;
import com.dao.RefreshChartDao;
import com.entity.Chart;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

@Component
public class RefreshChartDaoImpl implements RefreshChartDao {
    @Resource
    ChartDao chartDao;
    @Resource
    ChartRedisDao chartRedisDao;

    /**
     * 从mysql中获取统计数据保存到redis
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public void getCountStudentChartByClazz() throws SQLException, ClassNotFoundException {
        List<Chart> charts = chartDao.getCountStudentChartByClazz();//从mysql中拿出排行榜的数据
        chartRedisDao.pushCharts(charts, "classTop3byStudentAvgScore");//将数据存入redis
    }
}